﻿using System.Text.RegularExpressions;

namespace SFJDManagement
{
    public class VehicleType
    {
        public VehicleTypes enumType;
        public string fullName;
        public string smallBig = "小";

        public VehicleType(string str)
        {
            Regex regex1 = new Regex(@"^\w+(?<code>\d{4}).*$");
            Match match1 = regex1.Match(str);
            if (match1.Success)
            {
                string code = match1.Groups["code"].Value;
                int code1 = int.Parse(code.Substring(0, 1));
                string code2 = code.Substring(1, 2);
                enumType = (VehicleTypes)code1;
                if(code1 == 2)
                {
                    fullName = VehicleTypes.越野汽车.ToString();
                }else if (code1 < 5)
                {
                    TruckTypes truckType = GetTruckTypes(code2);
                    fullName = truckType.ToString() + enumType.ToString();
                    if((int)truckType > 1)
                    {
                        smallBig = "大";
                    }
                }else if(code1 == 6)
                {
                    BusTypes busType = GetBusTypes(code2);
                    fullName = busType.ToString() + enumType.ToString();
                    if((int)busType > 1)
                    {
                        smallBig = "大";
                    }
                }else if(code1 == 7)
                {
                    fullName = "小" + enumType.ToString();
                }
            }
            else
            {
                if(str == "自行车")
                {
                    enumType = VehicleTypes.自行车;
                }else if(Regex.IsMatch(str, @"^.*(两|二).*电.*$"))
                {
                    enumType = VehicleTypes.两轮电动车;
                }
                else
                {
                    enumType = VehicleTypes.轿车;
                }
                fullName = enumType.ToString();
            }
        }

        public enum VehicleTypes
        {
            载货汽车 = 1,
            越野汽车 = 2,
            自卸汽车 = 3,
            牵引汽车 = 4,
            专用汽车 = 5,
            客车 = 6,
            轿车 = 7,
            半挂车 = 9,
            自行车 = 10,
            两轮电动车 = 11,
            三轮电动车 = 12,
            两轮摩托车 = 13,
            三轮摩托车 = 14,
            四轮电动车 = 15,
            其它车辆 = 16
        }

        private TruckTypes GetTruckTypes(string code)
        {
            int load = int.Parse(code);
            if(load < 2)
            {
                return TruckTypes.微型;
            }else if(load < 6)
            {
                return TruckTypes.轻型;
            }else if(load < 14)
            {
                return TruckTypes.中型;
            }
            else
            {
                return TruckTypes.重型;
            }
        }

        private BusTypes GetBusTypes(string code)
        {
            int lenght = int.Parse(code);
            if(lenght < 35 & lenght > 13)
            {
                return BusTypes.微型;
            }else if(lenght < 70 & lenght >= 35)
            {
                return BusTypes.小型;
            }else if(lenght < 99 & lenght >= 70)
            {
                return BusTypes.中型;
            }
            else
            {
                return BusTypes.大型;
            }
        }

        public enum TruckTypes
        {
            微型,轻型,中型,重型
        }

        public enum BusTypes
        {
            微型,小型,中型,大型
        }
    }
}
